package com.ai.sb.controller;
import com.ai.sb.dto.PrizeDto;
import com.ai.sb.mobile.OneS;
import com.ai.sb.model.SbPrize;
import com.ai.sb.service.SbPrizeService;
import com.ai.sb.util.Result;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2018/06/09.
*/
@Api(value = "奖品管理接口",tags = {"奖品管理"})
@RestController
@RequestMapping("/sb/prize")
public class SbPrizeController {
    @Resource
    private SbPrizeService sbPrizeService;

    @ApiOperation(value = "碎冰概率获得奖品" ,notes = "参数：userId,recordType")
    @PostMapping("receivePrize")
    public synchronized Result receivePrize(@RequestBody PrizeDto prizeDto){
        return sbPrizeService.receivePrize(prizeDto.getUserId(),prizeDto.getRecordType());
    }

    @ApiOperation(value = "领取流量" ,notes = "参数：userId，prizeId")
    @PostMapping("receiveFlow")
    public synchronized Result receiveFlow(@RequestBody PrizeDto prizeDto){
        return sbPrizeService.receiveFlow(prizeDto);
    }

    @ApiOperation(value = "查询可兑换流量情况" ,notes = "参数：userId")
    @PostMapping("selFlow")
    public Result selFlow(@RequestBody PrizeDto prizeDto){
        return sbPrizeService.selFlow(prizeDto.getUserId());
    }

    @ApiOperation(value = "查询我的奖品" ,notes = "参数：userId")
    @PostMapping("selMyPrize")
    public Result selMyPrize(@RequestBody PrizeDto prizeDto){
        return sbPrizeService.selMyPrize(prizeDto.getUserId());
    }

    @PostMapping("tttt")
    public Result tttt(@RequestBody JSONObject jsonObject){
       if(OneS.isToFlow){
           return Result.fail("已经执行过");
       }
        OneS.isToFlow = true;
       return sbPrizeService.bb();
    }
}
